<?php

	session_start();

	require('setlang.php');
	require('Models/connectBDD.php');
	require('Models/basics.php');
	require('Models/formerrors.php');
	require('Models/location.php');

	require('Models/ariane.php');
	
	$Ariane = getArianeGenealogy();

	$connexion = PDO_BDD_connect();
	
	if (!isset($_POST['ownerId']) || !isset($_POST['locationId']))
	{
		header("Location:index.php");
	}
	//Si on valide l'envoi et que les champs sont correctes, on envoie via la fonction mail
	if (isset($_POST['valider']))
	{
		$errors = getFormErrors(array("e-mail","nom","mail","sujet","texte"),"POST");
		if (empty($errors))
		{
			$headers = "From: ".$_POST['nom']." (".$_POST['mail'].")";
			$sujetdefaut = $_POST["nom"]." vous demande des informations à propos de votre location : ".GetLocationInformations($connexion,$_POST['locationId'])->nom."\n";
			if (isOwner($connexion,$_POST['ownerId']))
			{
				$ownermail = getMailOfOwner($connexion,$_POST['ownerId'])->mail;
			}
			@mail($ownermail,$sujetdefaut.$_POST['sujet'],$_POST['texte'],$headers);
		}
	}
	
	require('Views/contactOwner.php');
	

?>
